function convertToStarsArray(stars) {
  stars = stars+ "";
  var num = stars.toString().substring(0, 1);
  var array = [];
  for (var i = 1; i <= 5; i++) {
    if (i <= num) {
      array.push(1);
    } else {
      array.push(0);
    }
  }
  return array;
}

// 访问豆瓣API的公用方法
function http(url,callBack) {
  wx.request({
    url: url,
    header: {
      "Content-Type":""
    },
    method: "GET",
    success: (res) => {
      callBack(res.data);
    },
    fail: (err) => {}
  })
}

// 演员名字用“/”拼接
function convertToCastString(casts){
  var castsjoin = "";
  for(var idx in casts){
    castsjoin = castsjoin + casts[idx].data[0].name + "/";
  }
  return castsjoin.substring(0,castsjoin.length-2);
}

function convertToCastInfos(casts){
  var castsArray = [];
  for(var idx in casts){
    var cast = {
      // img: casts[idx].avatars?casts[idx].avatars.large: "",
      img: "/images/cost.jpg",
      name:casts[idx].data[0].name
    }
    castsArray.push(cast);
  }
  return castsArray;
}
module.exports = {
  convertToStarsArray: convertToStarsArray,
  http: http,
  convertToCastString:convertToCastString,
  convertToCastInfos:convertToCastInfos
}